<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--suppress ALL-->
<html xmlns:th="http://www.thymeleaf.org" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<base th:href="@{/}"><!-- 不用base就使用th:src="@{/js/jquery.min.js} -->
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
	<title>天天生鲜-用户中心</title>
	<link rel="stylesheet" type="text/css" href="css/reset.css">
	<link rel="stylesheet" type="text/css" href="css/main.css">
	<script type="text/javascript" src="/js/jquery-1.12.4.min.js"></script>
	<script src="/layui/layui.js"></script>
	<style>
		.bbb {
			background: #8fce00;
			background-image: -webkit-linear-gradient(top, #8fce00, #38761d);
			background-image: -moz-linear-gradient(top, #8fce00, #38761d);
			background-image: -ms-linear-gradient(top, #8fce00, #38761d);
			background-image: -o-linear-gradient(top, #8fce00, #38761d);
			background-image: linear-gradient(to bottom, #8fce00, #38761d);
			-webkit-border-radius: 60;
			-moz-border-radius: 60;
			border-radius: 60px;
			font-family: Arial;
			color: black;
			font-size: 2px;
			padding: 3px 7px 3px 7px;
			text-decoration: none;
		}

		.bbb {
			background: #8fce00;
			background-image: -webkit-linear-gradient(top, #8fce00, white);
			background-image: -moz-linear-gradient(top, #8fce00, white);
			background-image: -ms-linear-gradient(top, #8fce00, white);
			background-image: -o-linear-gradient(top, #8fce00, white);
			background-image: linear-gradient(to bottom, #8fce00, white);
			text-decoration: none;
		}
	</style>
</head>
<body>
<div class="header_con">
	<div class="header">
		<div class="welcome fl">欢迎来到天天生鲜!</div>
		<div class="fr">
			<div class="login_info fl">
				欢迎您：<em>张 山</em>
			</div>
			<div class="login_btn fl">
				<a href="/index">首页</a>
				<a href="/toLogin" th:if="${session.user==null}">登录</a>
				<span th:if="${session.user!=null}" th:text="'欢迎：'+${session.user.userEmail}" style="color: black"></span>
				<span>|</span>
				<a href="/toRegister">注册</a>
			</div>
			<div class="user_link fl">
				<span>|</span>
				<a href="/toUserCenterInfo">用户中心</a>
				<span>|</span>
				<a href="/carttable/myCart">我的购物车</a>
				<span>|</span>
				<a href="/focustable/myFocus">我的收藏</a>
				<span>|</span>
				<a href="/toUserCenterOrder?currentPage=1&pageSize=4">我的订单</a>
			</div>
		</div>
	</div>
</div>

	<div class="search_bar clearfix">
		<a href="index.html" class="logo fl"><img src="images/logo.png"></a>
		<div class="sub_page_name fl">|&nbsp;&nbsp;&nbsp;&nbsp;用户中心</div>
		<div class="search_con fr">
			<form action="/goodstable/searchForGoods">
				<input type="text" class="input_text fl" name="goodsName" placeholder="搜索商品">
				<input type="submit" class="input_btn fr" name="" value="搜索">
			</form>
		</div>		
	</div>

	<div class="main_con clearfix">
		<div class="left_menu_con clearfix">
			<h3>用户中心</h3>
			<ul>
				<li><a href="/toUserCenterInfo">· 个人信息</a></li>
				<li><a href="/toUserCenterOrder?currentPage=1&pageSize=4">· 全部订单</a></li>
				<li><a href="/toUserCenterSite" class="active">· 收货地址</a></li>
			</ul>
		</div>
		<div class="right_content clearfix">
				<h3 class="common_title2">收货地址</h3>
				<div class="site_con">
					<dl>
						<form action="/address/setDefault">
							<div th:each="address,index:${addresses}">
								<div th:if="${index.index==0}">
									<dt>默认地址：<a href="/toUserCenterAdmin"><button type="button" class="bbb" style="float: right">管理</button></a></dt>
									<!--								<dd>北京市 海淀区 东北旺西路8号中关村软件园 （李思 收） 182****7528</dd>-->
									<dd style="color: #37ab40">[[${address.address}]]<em>　收货人：<a>[[${address.userName}]]</a></em><em>　联系电话：<a>[[${address.phone}]]</a></em></dd>
									<dt>候选地址：</dt>
								</div>
								<div th:if="${index.index!=0}">
									<dd><input type="radio" name="id" th:value="${address.id}">[[${address.address}]]<em>　收货人：<a>[[${address.userName}]]</a></em><em>　联系电话：<a>[[${address.phone}]]</a></em>
										<button style="float: right" type="submit" th:if="${index.last}" class="bbb">设置为默认</button></dd>
								</div>
							</div>
						</form>
					</dl>					
				</div>
				<h3 class="common_title2">编辑地址</h3>
				<div class="site_con">
					<div class="form_group">
						<label>收货人：</label>
						<input id="userName" type="text" name="userName">
						<span id="sp1"></span>
					</div>
					<div class="form_group form_group2">
						<label>收货地址：</label>
						<textarea id="address" class="site_area"></textarea>
						<span id="sp2"></span>
					</div>
					<div class="form_group">
						<label>手机号码：</label>
						<input id="phone" type="text" name="">
						<span id="sp3"></span>
					</div>
					<input type="button" id="btn" name="" value="提交" class="info_submit">
				</div>
		</div>
	</div>



	<div class="footer">
		<div class="foot_link">
			<a href="#">关于我们</a>
			<span>|</span>
			<a href="#">联系我们</a>
			<span>|</span>
			<a href="#">招聘人才</a>
			<span>|</span>
			<a href="#">友情链接</a>		
		</div>
		<p>CopyRight © 2016 北京天天生鲜信息技术有限公司 All Rights Reserved</p>
		<p>电话：010-****888    京ICP备*******8号</p>
	</div>
	
</body>
<script>
	$("#userName").blur(function (){
		var userName = $("#userName").val();
		var url = "/address/checkAddressConsignee";
		var param = {"userName":userName};
		$.getJSON(url,param,function (data){
			if (data.code==200){
				$("#sp1").html(data.message);
				$("#sp1").attr('style','color:green');
			}else{
				$("#sp1").html(data.message);
				$("#sp1").attr('style','color:red');
			}
		});
	});
	$("#address").blur(function (){
		var address = $("#address").val();
		var url = "/address/checkAddressAddress";
		var param = {"address":address};
		$.getJSON(url,param,function (data){
			if (data.code==200){
				$("#sp2").html(data.message);
				$("#sp2").attr('style','color:green');
			}else{
				$("#sp2").html(data.message);
				$("#sp2").attr('style','color:red');
			}
		});
	});
	$("#phone").blur(function (){
		var phone = $("#phone").val();
		var url = "/address/checkAddressPhone";
		var param = {"phone":phone};
		$.getJSON(url,param,function (data){
			if (data.code==200){
				$("#sp3").html(data.message);
				$("#sp3").attr('style','color:green');
			}else{
				$("#sp3").html(data.message);
				$("#sp3").attr('style','color:red');
			}
		});
	});
	$("#btn").click(function (){
		var userName = $("#userName").val();
		var address = $("#address").val();
		var phone = $("#phone").val();
		var url = "/address/addAddress";
		var param = {"userName":userName,"address":address,"phone":phone};
		$.get(url,param,function (data){
			if (data.code==200){
				layer.msg(data.message);
				location.href="/toUserCenterSite";
			}else {
				layer.msg(data.message);
			}
		},"json");
	});

</script>
</html>